package me.helong.videolive;

import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketSession;

import java.util.HashMap;
import java.util.Map;

@Component
public class WebSocketSessionDataStorage {
    private final Map<String, Map<String, Object>> sessionDataMap = new HashMap<>();

    public synchronized Map<String, Object> getSessionData(WebSocketSession session) {
        if (sessionDataMap.containsKey(session.getId())) {
            return sessionDataMap.get(session.getId());
        } else {
            Map<String, Object> data = new HashMap<>();
            sessionDataMap.put(session.getId(), data);
            return data;
        }
    }

    public synchronized void removeSessionData(WebSocketSession session) {
        sessionDataMap.remove(session.getId());
    }
}
